const coffeesqopen = (coffee_number) => {
  get_coffeesqopen(coffee_number)
  return
  let uid = wx.getStorageSync('userInfo').id;
  if (uid == '4672' || uid == '100' || uid == '4675' || uid == '5285') {
    get_coffeesqopen(coffee_number)
  } else {
    coffeeopendoor(coffee_number)
  }
}

let get_coffeesqopen = (coffee_number) =>{
  getApp().globalData.posts('/index.php/api/app/user/sorting/ouyoung_api/coffeesqopen', {
    device_number: coffee_number
  }).then(res => {
    if (res.data.code == 2) {
      let extraData = res.data.data.extraData;
      let order_no = res.data.data.order_no;
      wx.setStorageSync('extraData_info', {
        extraData,
        order_no,
        coffee_number
      })
      wx.navigateTo({
        url: '/pages/product/among',
      })
    } else if (res.data.code == 1) {
      getApp().globalData.coffee_order_no = res.data.data.order_no;
      let pages = getCurrentPages();
      let nowPage = pages[pages.length - 1];
      nowPage.setData({
        close: true
      })
    } else {
      getApp().showModal(res.data.msg)
    }
  })
}

let coffeeopendoor = (coffee_number) =>{
  getApp().globalData.posts('/index.php/api/app/user/sorting/ouyoung_api/coffeeopendoor', {
    device_number: coffee_number
  }).then(res => {
    if (res.data.code != 1) {
      getApp().showToast(res.data.msg)
    }
  })
}

module.exports = {
  coffeesqopen,
}